<template>
  <div class='general-container'>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :defaults.sync="showColumn"
               :permission="permissionList"
               :page.sync="page"
               :before-open="beforeOpen"
               @sortable-change="sortableChange"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @row-dblclick="handleRowDBLClick"
               @filter="filterChange"
               @sort-change="sortChange"
               @on-load="getDynamicForm"
               >
      <template slot-scope="scope" slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm001' && permission.sys_dynamic_001_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm002' && permission.sys_dynamic_002_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm003' && permission.sys_dynamic_003_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm004' && permission.sys_dynamic_004_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm005' && permission.sys_dynamic_005_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm006' && permission.sys_dynamic_006_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm007' && permission.sys_dynamic_007_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm008' && permission.sys_dynamic_008_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm009' && permission.sys_dynamic_009_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm010' && permission.sys_dynamic_010_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm011' && permission.sys_dynamic_011_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm012' && permission.sys_dynamic_012_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm013' && permission.sys_dynamic_013_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm014' && permission.sys_dynamic_014_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm015' && permission.sys_dynamic_015_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm016' && permission.sys_dynamic_016_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_017_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="formCode && formCode == 'dynamicForm018' && permission.sys_dynamic_018_batch_delete"
                   @click="handleDelete">删 除
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
          <el-button v-if="currentForm.isFlowFlag == '1' && currentForm.flowBeginWay == '0' && scope.row.flowStatus == '0'" type="text"
                size="small"
                icon="el-icon-s-operation"
                @click="startFlow(scope.row)">启动流程
          </el-button>
          <el-button v-if="currentForm.isFlowFlag == '1' && scope.row.flowStatus == '1'" type="text"
                size="small"
                icon="el-icon-s-operation"
                @click="openFlowCharts(scope.row)"
                >流程中
          </el-button>
          <el-button v-if="currentForm.isFlowFlag == '1' && scope.row.flowStatus == '2'" type="text"
                size="small"
                icon="el-icon-s-operation"
                >流程结束
          </el-button>
      </template>   
      <template slot="menuRight">
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm001' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm0002' && permission.sys_dynamic_002_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm003' && permission.sys_dynamic_003_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>
        <el-button type="default" 
              v-if="formCode && formCode == 'dynamicForm017' && permission.sys_dynamic_001_download"
              @click.stop="exportExcel" 
              icon="el-icon-download" 
              circle size="small">
        </el-button>

      </template>
    </avue-crud>

    <!-- 
      流程图对话框
     -->
    <el-dialog title="流程信息" width="90%" style="height:100%" @opened="flowChartDialogOpened" :close-on-click-modal='false' :visible.sync="flowCharts">
      <el-tabs type="border-card" v-model="activeName"  @tab-click="handleTabChange">
        <el-tab-pane name="flowChart">
          <span slot="label"><svg-icon style="font-size:10px;" iconClass="flowIcon"/>流程图</span>
          <flow-charts ref="flowChart"></flow-charts>
        </el-tab-pane>
        <el-tab-pane name="flowTimeline">
          <span slot="label"><i class="el-icon-time"></i>流程处理记录</span>
          <flow-process-timeline ref="flowTimeline"></flow-process-timeline>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button icon="el-icon-close"  size="small" @click="flowCharts = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {updateGeneralBizDemand} from '@/api/general/biz/generalBizDemandApi';
import {querySysDynamicForm,querySysDynamicFormListPage} from '@/api/system/sysDynamicFormApi';
import {exportDynamicFormExcel,saveOrUpdateDynamicForm,saveOrUpdateDynamicFormList,saveDynamicForm,deleteDynamicForm,queryDynamicForm,queryDynamicFormListPage,updateDynamicForm,deleteDynamicFormList} from '@/api/system/dynamicFormApi';
import {mapGetters} from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import {filterFormat} from '@/util/util';
import FlowCharts from '@/views/general/flow/generalFlowProcessCharts.vue';
import FlowProcessTimeline from '@/views/general/flow/generalFlowProcessTimeline.vue';
export default {
  components: {
    FlowCharts,
    FlowProcessTimeline
  },
  props: ['formCode'],
  data() {
    return {
      //如果做流程表单 请将次开关设置为true，否则设置为false
      isFlow: true,
      flowArea: {},
      currentRow: {},

      form: {},
      selectionList: [],
      showColumn: [],
      option: {},
      data: [],
      // 请求参数区
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: {},
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {},
      //动态表单参数
      currentForm: {},
      formId: '',
      formCode: '',
      bizCode: '',
      bizName: '',
      loading: false,
      
      // 流程图
      flowCharts: false,
      activeName: 'flowChart',
      dynamicFormData: {},
    };
  },
  computed: {
    ...mapGetters(['userInfo','permission']),
    permissionList() {
      if(this.formCode == 'dynamicForm001'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_001_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_001_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_001_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_001_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_001_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_001_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm002'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_002_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_002_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_002_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_002_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_002_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_002_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm003'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_003_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_003_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_003_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_003_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_003_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_003_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm004'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_004_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_004_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_004_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_004_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_004_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_004_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm005'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_005_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_005_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_005_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_005_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_005_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_005_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm006'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_006_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_006_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_006_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_006_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_006_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_006_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm007'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_007_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_007_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_007_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_007_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_007_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_007_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm008'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_008_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_008_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_008_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_008_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_008_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_008_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm009'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_009_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_009_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_009_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_009_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_009_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_009_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm010'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_010_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_010_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_010_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_010_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_010_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_010_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm011'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_011_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_011_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_011_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_011_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_011_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_011_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm012'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_012_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_012_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_012_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_012_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_012_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_012_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm013'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_013_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_013_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_013_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_013_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_013_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_013_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm014'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_014_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_014_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_014_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_014_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_014_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_014_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm015'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_015_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_015_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_015_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_015_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_015_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_015_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm016'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_016_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_016_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_016_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_016_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_016_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_016_search, false)
        };
      }
      else if(this.formCode == 'dynamicForm017'){
        return {
          addBtn: this.vaildData(this.permission.sys_dynamic_017_add, false),
          viewBtn: this.vaildData(this.permission.sys_dynamic_017_view, false),
          delBtn: this.vaildData(this.permission.sys_dynamic_017_delete, false),
          editBtn: this.vaildData(this.permission.sys_dynamic_017_edit, false),
          printBtn: this.vaildData(this.permission.sys_dynamic_017_print, false),
          searchBtn:this.vaildData(this.permission.sys_dynamic_017_search, false)
        };
      }
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({id : ele.id});
      });
      return ids;
    } 
  },
  methods: { 
    /*****流程处理开始*****/
    /**
     * 启动流程
     */
    startFlow(row){
      if(!this.currentForm.flowId){
        this.$message({
          customClass:'zZindex',
          type: 'error',
          message: '启动流程时，流程ID不能为空!'
        });
        return false;
      }
      if(!row.title){
        this.$message({
          customClass:'zZindex',
          type: 'error',
          message: '启动时流程表单应包含：标题[title]字段!'
        });
        return false;
      }
      this.$confirm('确定要发起流程?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.currentRow = row;
        this.flowArea.flowExtData = this.flowExtInfo; 
        //flowOptFlag 1-开始启动 2-处理流程 3-回退
        this.flowArea.isFlow = true;
        this.flowArea.flowOptFlag = '1';
        this.flowArea.flowId = this.currentForm.flowId;
        this.processFlow(row); 
      }).catch(() => {});
    },
    /**
     * 启动流程，执行流程方法
     */
    processFlow(row){
      const loading = this.$loading({
        lock: true,
        text: '流程启动中....',
        spinner: 'el-icon-loading',
      });
      let tmpRow=JSON.stringify(row).replace(/\$/g,'_');
      this.reqParams.singleBody = JSON.parse(tmpRow);
      //flowStatus 0-未开始 1-流程中 2-流程结束
      this.reqParams.singleBody.flowStatus = '1'
      this.reqParams.flowArea = this.flowArea
      this.reqParams.extBody = {
        id: row.id,
        bizCode: row.bizCode
      }
      this.commonData = reqCommonMsg(this.reqParams)
      updateDynamicForm(this.commonData).then(() => {
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '流程成功启动!'
        });
        this.onLoad(this.page);
        loading.close();
      }, error => {
        //this.$console.log(error); 
        loading.close();
      });
    },
    /*****流程处理结束*****/

    //加载列表数据
    onLoad(page) {
      if(!this.singleBody.bizCode){
        this.singleBody.bizCode = this.currentForm.bizCode
      }
      this.loading = true;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: page.currentPage, 
        pageSize: page.pageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryDynamicFormListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false; 
      });
    },
    /**
     * 新增记录
     */
    rowSave(row, done, loading) {
      row.bizCode=this.currentForm.bizCode;
      row.bizName=this.currentForm.bizName;
      row.formId = this.currentForm.id
      row.formCode = this.currentForm.formCode
      row.flowId = this.currentForm.flowId
      //flowStatus 0-未开始 1-流程中 2-流程结束
      row.flowStatus = '0'
      let tmpRow=JSON.stringify(row).replace(/\$/g,'_')
      this.reqParams.singleBody = JSON.parse(tmpRow);
      this.reqParams.flowArea = {
        flowBeginWay: this.currentForm.flowBeginWay,
        isFlow: true,
        flowOptFlag: '1',
        flowId: this.currentForm.flowId
      }
      this.commonData = reqCommonMsg(this.reqParams)
      saveDynamicForm(this.commonData).then(() => {
        done();
        this.singleBody={};
        this.onLoad(this.page);
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        loading();
      });         
      //this.$console.log("row = ",row ,loading)
    },
    /**
     * 更新记录
     */
    rowUpdate(row, index, done, loading) { 
      let tmpRow=JSON.stringify(row).replace(/\$/g,'_')
      this.reqParams.singleBody = JSON.parse(tmpRow);
      this.reqParams.extBody = {
        id: row.id,
        bizCode: row.bizCode
      }
      this.commonData = reqCommonMsg(this.reqParams)
      updateDynamicForm(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.onLoad(this.page);
        this.$message({
          customClass:'zZindex',
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        loading();
      });
    },
    rowDel(row) {
      // 判断是否有启动后状态的流程，这些不能删除
      if(row.flowStatus !== '0'){
        this.$message.warning('启动后的流程不能删除');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteDynamicForm(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }); 
    },

    searchReset() {
      this.conditions =[];
      this.singleBody = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad(this.page);
      done();
    },
    refreshChange(){
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }

      // 判断是否有启动后状态的流程，这些不能删除
      for(let item of this.selectionList){
        if(item.flowStatus !== '0'){
          this.$message.warning('启动后的流程不能删除');
          return;
        }
      }

      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.reqParams.singleBody.bizCode = this.currentForm.bizCode;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteDynamicFormList(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            customClass:'zZindex',
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    
    /**
     * 打开编辑、查询弹窗前查询记录
     */
    beforeOpen(done, type) {
      this.reqParams =  {
        singleBody: {
          id:this.form.id,
          bizCode: this.currentForm.bizCode
        }
      }
      let commonData = reqCommonMsg(this.reqParams)
      if (['edit', 'view'].includes(type)) {
        queryDynamicForm(commonData).then(res => {
          this.form = res.data.body.singleBody;
          //this.$console.log('this.option===>', this.option)
          let disabled = false;
          if(this.form.flowStatus !== '0'){
            disabled = true;
          }
          
          for(let i in this.option.column){
            this.option.column[i].disabled = disabled;
          }

          for(let i in this.option.group){
            for(let j in this.option.group[i].column){
              this.option.group[i].column[j].disabled = disabled;
            }
          }

          done();
        });
      }else{
        for(let i in this.option.column){
          this.option.column[i].disabled = false;
        }

        for(let i in this.option.group){
          for(let j in this.option.group[i].column){
            this.option.group[i].column[j].disabled = false;
          }
        }
        done();
      }
      
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad(this.page);
    },
    sortChange(val){
      this.orderRules=val
      this.onLoad(this.page);
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick (row, event) {
      this.$refs.crud.rowView(row,row.$index);
    },
    /**
     * 导出Excel
     */
    exportExcel() {
      this.singleBody.bizCode = this.currentForm.bizCode;
      this.singleBody.formId = this.currentForm.id;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage:1, 
        pageSize: 100
      }
      //this.$console.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportDynamicFormExcel(this.commonData);
    },

    /**
     * 获取动态表单
     */
    getDynamicForm(){
      this.loading = true; 
      this.reqParams =  {
        singleBody: {
          formCode: this.formCode
        }
      }
      let commonData = reqCommonMsg(this.reqParams)
      querySysDynamicFormListPage(commonData).then(res => {
        if(res.data.body.listBody.length > 0){
          let data = res.data.body.listBody[0];
          if(JSON.stringify(this.option) != data.formJson){
            data.formJson = data.formJson.replace('{tenantId}', localStorage.getItem('tenantId'))
            this.option  = JSON.parse(data.formJson);
            this.$setStore({name: this.userInfo.userId + this.formCode +'FormJson', content: this.option});
          }
          this.currentForm = data;
          this.onLoad(this.page);
        }
        else{
          this.$message({
            customClass:'zZindex',
            type: 'warning',
            message: '未找到表单定义记录!'
          });
        }
        // this.loading = false; 
      }, error => {
        this.loading = false; 
      });
    },
    /**
     * 打开流程图对话框
     */
    openFlowCharts(row){
      this.dynamicFormData = row;
      this.flowCharts = true;
    },
    /**
     * 流程对话框打开之后 获取数据
     */
    flowChartDialogOpened(){
      this.$refs.flowChart.getDynamicFormFlowChartData(this.dynamicFormData.flowId, this.dynamicFormData.id);
    },
    /**
     * 切换流程图标签时
     */
    handleTabChange(tab, event) {
      if(tab.name == 'flowTimeline'){
        this.$refs.flowTimeline.loadDynamicFormTimelineData(this.dynamicFormData.id);
      }
    },
  },
  created() {
    if(this.$getStore({name: this.userInfo.userId + this.formCode +'FormJson'})) {
      this.option = this.$getStore({name: this.userInfo.userId + this.formCode +'FormJson'})
    }
    // 获取字典参数配置。
    // this.getDynamicForm();
    this.showColumn = this.$getStore({name: this.userInfo.userId  + this.formCode +'Column'});
    // this.onLoad(this.page)
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({name:  this.userInfo.userId + this.formCode +'Column', content: this.showColumn});
      },
      deep: true
      //this.$setStore({name: this.userInfo.userId + this.formCode +'Column', content: this.showColumn});
    }
  }
};
</script>
<style>
.general-container .avue-crud__search .avue-form__menu--center{
 padding-top: 0px !important;
}

</style>